#!/usr/bin/env bash
set -x

# Fast finish the PR.
echo ""
(curl https://raw.githubusercontent.com/conda-forge/conda-forge-ci-setup-feedstock/master/recipe/conda_forge_ci_setup/ff_ci_pr_build.py |
    python - -v --ci "travis" "${TRAVIS_REPO_SLUG}" "${TRAVIS_BUILD_NUMBER}" "${TRAVIS_PULL_REQUEST}") || exit 1

# Remove homebrew.
echo ""
echo "Removing homebrew from Travis CI to avoid conflicts."
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew
chmod +x ~/uninstall_homebrew
~/uninstall_homebrew -fq
rm ~/uninstall_homebrew

# Install Miniconda.
echo ""
echo "Installing a fresh version of Miniconda."
curl -L https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh > ~/miniconda.sh
bash ~/miniconda.sh -b -p ~/miniconda
source ~/miniconda/bin/activate root

# Configure conda.
echo ""
echo "Configuring conda."
conda config --add channels conda-forge
conda config --set show_channel_urls true
conda install --yes --quiet "conda>4.7.12" conda-forge-ci-setup=2.* conda-forge-pinning networkx=2.3 "conda-build>=3.16"
source run_conda_forge_build_setup

# Find the recipes from master in this PR and remove them.
echo ""
echo "Finding recipes merged in master and removing them from the build."
pushd ./recipes > /dev/null
git ls-tree --name-only master -- . | xargs -I {} sh -c "rm -rf {} && echo Removing recipe: {}"
popd > /dev/null
echo ""

# We just want to build all of the recipes.
python .ci_support/build_all.py
